package video.dataAndType

fun main(args: Array<String>) {

    //智能类型转换
    val p: Parent = Child()
    if (p is Child) {
        p.todo()
    }

    val string: String? = "hello"
    if (string is String) {
        println(string.length)
    }

    //防止强转出现异常,需要 as? 转换失败返回null
    val p1: Parent = Parent()
    val child = p1 as? Child
    child?.todo()
}


open class Parent

class Child : Parent() {
    fun todo() {
        println("child-->todo")
    }
}
